package com.jshx.sz.gdjt.client;

import java.io.File;

import android.app.ActivityManager;
import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.SharedPreferences;

import com.jshx.sz.gdjt.activity.GetTaskListActivity;
import com.jshx.sz.gdjt.constant.ApplicationGlobal;
import com.jshx.sz.gdjt.db.DataBaseUtil;
import com.jshx.sz.gdjt.util.FileUtils;

/**
 * 程序application对象
 * @author caxiang
 * @time 2013-08-20
 */
public class ClientApplication extends Application 
{
	private static final String TAG = "ClientApplication";
	
	/**
	 * 应用上下文对象
	 */
	private static Context context;
	
	
	@Override
	public void onCreate() 
	{
		super.onCreate();
		context = this;
		ApplicationGlobal.APPPACKAGENAME = context.getPackageName();
		ActivityManager am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);  
		ComponentName cn = am.getRunningTasks(1).get(0).topActivity;  
		String packageName = cn.getPackageName();  
		if(packageName != null && packageName.length() > 0)
		{
			ApplicationGlobal.APPPACKAGENAME = packageName;
		}
		//创建目录
		FileUtils fu = new FileUtils();
		fu.createSDDir("");
		//图片目录
		fu.createSDDir(File.separatorChar + ApplicationGlobal.imageBaseFoldName);
		DataBaseUtil.initDBUtil(getApplicationContext());
		
	}

	/**
	 * 获取应用app上下文对象
	 * @return
	 */
	public static Context getAppInstance()
	{
		return context;
	}
	
	/**
	 * 获取本地存储对象
	 * @return
	 */
	public static SharedPreferences getSharePre()
	{
		return context.getSharedPreferences(ApplicationGlobal.SPDATANAME, Context.MODE_PRIVATE);
	}
	
	@Override
	public void onTerminate() {
		super.onTerminate();
	}

	@Override
	public void onLowMemory() {
		super.onLowMemory();
	}
}
